﻿#ifndef DAOCLOUDSCOS_H
#define DAOCLOUDSCOS_H
#include "daoclouds.h"

namespace qcloud_cos
{
    class CosConfig;
    class CosResult;
    class GetBucketResp;
} // namespace qcloud_cos

/// @brief 对象存储 DAO (腾讯云 COS)
///
class DaoCloudsCos: public DaoClouds
{
private:
    qcloud_cos::CosConfig* m_config = nullptr;

public:
    DaoCloudsCos();
    ~DaoCloudsCos();

    QList<MyBucket> login(const QString& secretId, const QString& secretKey)
            override;

    QList<MyBucket> buckets() override;

    bool isBucketExists(const QString& bucketName) override;
    QString getBucketLocation(const QString& bucketName) override;

    void putBucket(const QString& bucketName, const QString& location)
            override;
    void deleteBucket(const QString& bucketName) override;

    QList<MyObject> getObjects(const QString& bucketName, const QString& dir)
            override;

    bool isObjectExists(const QString& bucketName, const QString& key);

    void putObject(
            const QString& bucketName,
            const QString& key,
            const QString& localPath,
            const TransProgressCallback& callback) override;

    void getObject(
            const QString& bucketName,
            const QString& key,
            const QString& localPath,
            const TransProgressCallback& callback) override;

private:
    QList<MyObject> getDirList(
            qcloud_cos::GetBucketResp& resp,
            const QString& dir);
    QList<MyObject> getFileList(
            qcloud_cos::GetBucketResp& resp,
            const QString& dir);
    void throwError(const QString& code, qcloud_cos::CosResult& result);
    MyBucket getBucketByName(const QString& bucketName);
};

#endif // DAOCLOUDSCOS_H
